package hr.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import hr.entity.DO.EmployeeProbationReviewDO;
import hr.entity.vo.EmployeeProbationVo;
import hr.entity.vo.ProbationReviewVo;
import hr.service.EmployeesService;
import hr.service.ProbationreviewService;
import hr.utils.Result.Result;
import hr.utils.Result.ResultUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 试用期审查表 前端控制器
 * </p>
 *
 * @author zzh
 * @since 2023-12-10
 */
@Tag(name = "试用期管理")
@RestController
@Slf4j
@RequestMapping("/probationReview")
public class ProbationreviewController {
    @Autowired
    private ProbationreviewService probationreviewService;

    @Autowired
    private EmployeesService employeesService;

    @Operation(summary = "获取所有数据")
    @PostMapping("/getAll")
    public Result<Object> getAll(@RequestBody EmployeeProbationVo employeeProbationVo) {
        HashMap<String, Object> map = new HashMap<>();
        List<EmployeeProbationReviewDO> list = probationreviewService.getAll(employeeProbationVo);
        map.put("list", list);
//        IPage<Employee> pageInfo = new Page<>(employeeProbationVo.getPage(), employeeProbationVo.getLimit());
        long count = probationreviewService.getAllCount(employeeProbationVo);
        IPage<EmployeeProbationReviewDO> pageInfo = new Page<>(employeeProbationVo.getPage(), count);
        map.put("count", count);
        map.put("pageInfo", pageInfo);
        return ResultUtil.success(map);
    }

    @Operation(summary = "修改试用期状态")
    @PostMapping("/updateProbationStatus")
    public Result<Object> updateProbationStatus(@RequestBody ProbationReviewVo vo) {
        return probationreviewService.updateProbationStatus(vo) ? ResultUtil.success("修改员工试用期状态成功!") : ResultUtil.error("修改员工试用期状态失败，请重试!");
    }

    @Operation(summary = "删除试用期员工")
    @PostMapping("/deleteProbationReview/{probationId}")
    public Result<Object> deleteProbationReview(@PathVariable("probationId") Integer probationId) throws Exception {
        return probationreviewService.deleteByProbationId(probationId) ? ResultUtil.success("删除试用期员工成功!") : ResultUtil.success("删除试用期员工失败，请重试!");
    }
}
